"""
@Author: li
@Email: lijianqiao2906@live.com
@FileName: menu.py
@DateTime: 2025/07/06
@Docs: 菜单相关的 Pydantic Schema
"""

from pydantic import Field

from app.schemas.base import BaseRequest


class MenuBase(BaseRequest):
    """菜单基础 Schema"""

    name: str = Field(max_length=100, description="菜单名称 (前端路由名)")
    title: str = Field(max_length=100, description="菜单标题 (显示文本)")
    path: str | None = Field(default=None, max_length=200, description="路由路径")
    component: str | None = Field(default=None, max_length=200, description="组件路径")
    icon: str | None = Field(default=None, max_length=100, description="图标")
    parent_id: int | None = Field(default=None, description="父菜单ID")
    type: str = Field(max_length=20, description="菜单类型 (eg: directory, menu, button)")
    is_hidden: bool = Field(default=False, description="是否隐藏")
    is_keepalive: bool = Field(default=False, description="是否缓存")
    sort_order: int = Field(default=0, description="排序")
    permission_code: str | None = Field(default=None, max_length=100, description="绑定的权限编码")
    description: str | None = Field(default=None, description="描述")


class MenuCreate(MenuBase):
    """创建菜单 Schema"""

    pass


class MenuUpdate(BaseRequest):
    """更新菜单 Schema (所有字段可选)"""

    name: str | None = Field(default=None, max_length=100, description="菜单名称")
    title: str | None = Field(default=None, max_length=100, description="菜单标题")
    path: str | None = Field(default=None, max_length=200, description="路由路径")
    component: str | None = Field(default=None, max_length=200, description="组件路径")
    icon: str | None = Field(default=None, max_length=100, description="图标")
    parent_id: int | None = Field(default=None, description="父菜单ID")
    type: str | None = Field(default=None, max_length=20, description="菜单类型")
    is_hidden: bool | None = Field(default=None, description="是否隐藏")
    is_keepalive: bool | None = Field(default=None, description="是否缓存")
    sort_order: int | None = Field(default=None, description="排序")
    permission_code: str | None = Field(default=None, max_length=100, description="绑定的权限编码")
    description: str | None = Field(default=None, description="描述")


class MenuRead(MenuBase):
    """读取菜单 Schema"""

    id: int = Field(description="菜单ID")

    class Config:
        from_attributes = True


class MenuNode(MenuRead):
    """菜单树节点 Schema"""

    children: list["MenuNode"] = Field(default_factory=list, description="子菜单")
